// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

/** 添加新闻 */
export async function createProduct(options) {
  return request<{
    data;
  }>('/api/mjHomeProduct/add', {
    method: 'POST',
    data:(options || {}),
  });
}

/** 删除新闻 */
export async function removeProduct(options) {
    
    return request<{
      data;
    }>('/api/mjHomeProduct/delete', {
      method: 'POST',
      ...(options || {}),
    });
  }
  
  /** 首页产品详情 */
export async function product(options) {
  console.log(options,'-')
   const result = await request('/api/mjHomeProduct/queryByProductId', {
      method: 'POST',
      data: options,
    });
    console.log(result,'-')
    return { data: result.data, success: true }
  }
  
  
export async function updateProduct(options) {
    console.log(options,'----option')
    return request<{
      data;
    }>('/api/mjHomeProduct/edit', {
      method: 'POST',
      data:(options || {}),
    });
  }
  
/** 产品列表 */

export async function mjProduct() {
    const res = await  request<{
        data;
      }>('/api/mjProduct', {
        method: 'GET',
        data:( {}),
      });
      return res
    
}

//添加产品接口
export async function addProduct(options) {
    return request<{
      data;
    }>('/api/mjProduct/add', {
      method: 'POST',
      data:(options || {}),
    });
  }
  // 修改产品
  export async function editProduct(options) {
    return request<{
      data;
    }>('/api/mjProduct/edit', {
      method: 'POST',
      data:(options || {}),
    });
  }
    // 删除产品
    export async function deleteProduct(options) {
      return request<{
        data;
      }>('/api/mjProduct/delete', {
        method: 'POST',
        params:(options || {}),
      });
    }
    
    
    /** API相关内容 */
    
    /** api */
export async function addAttribute(options) {
  options.productId = 1;
  return request<{
    data;
  }>('/api/mjProductDetail/add', {
    method: 'POST',
    data:(options || {}),
  });
}

/** api */
export async function removeAttribute(options) {
    
    return request<{
      data;
    }>('/api/mjProductDetail/delete', {
      method: 'POST',
      params:(options || {}),
    });
  }
  
  /** api */
export async function queryAttributeList(options) {
  console.log(options,'-')
   const result = await request('/api/mjProductDetail/queryDetailByProductID', {
      method: 'POST',
      data: options,
    });
    console.log(result,'-')
    return { data: result.data, success: true }
  }
  
  /** api */
export async function updateAttribute(options) {
    console.log(options,'----option')
    return request<{
      data;
    }>('/api/mjProductDetail/edit', {
      method: 'POST',
      data:(options || {}),
    });
  }
  
  // 查询产品详情
  export async function queryDetailByProductIDORType(options) {
    const res = await  request<{
        data;
      }>('/api/mjProductDetail/queryDetailByProductIDORType', {
        method: 'POST',
        data:options
      });
      return res
}
export async function updateByProductIDType(options) {
  const res = await  request<{
      data;
    }>('/api/mjProductDetail/updateByProductIDType', {
      method: 'POST',
      data:options
    });
    return res
}

// 购物车api相关

// 获取购物车列表
export async function fetchCartList(data?: API.PageParams) {
  const result =  request<{ data: API.CartItem[] }>('/api/mjCar/queryByPage', {
    method: 'POST',
    data,
  });
  return result.data.records
}

// 创建购物车项
export async function createCartItem(data: API.CartItem) {
  return request<API.CartItem>('/api/mjCar/cart', {
    method: 'POST',
    data,
  });
}

// 更新购物车项
export async function updateCartItem(data: API.CartItem) {
  return request<API.CartItem>(`/api/cart/edit`, {
    method: 'PUT',
    data,
  });
}

// 删除购物车项
export async function deleteCartItem(id: number) {
  return request<{ success: boolean }>(`/api/cart/delete`, {
    method: 'DELETE',
    data: { id },
  });
}
